//
//  WCNNewPICCPreserveVC.m
//  WCN
//
//  Created by wsj2015 on 16/3/28.
//  Copyright © 2016年 ShanghaiCize Trade And Business Co., Ltd. All rights reserved.
//

#import "WCNNewPICCPreserveVC.h"
#import "WCButton.h"
#import "UINavigationItem+Offset.h"
#import "WCNMulTextTCell.h"
#import "WCNSwitchSexTCell.h"
#import "WCInfoEditView.h"
#import "NSString+Utilities.h"
#import "WCPickerView.h"
#import "WCNMulTextEditVC.h"
#import "WCDatePickerView.h"
#import "NSDate+Utilities.h"
#import "WCTSetTextTool.h"
#import "UILabel+Utilities.h"
#import "WCDrawBorderView.h"
#import "WCNCareRecordDetailFooterView.h"
#import "WCImageManager.h"
#import "WCNHospitalListVC.h"
#import "Account.h"
#import "WSJPickAndCustomCell.h"
#import "WSJPickView.h"
#import "JCAlertView.h"
#import "WSJCareNursingPeopleView.h"
#import "WCNNurseModel.h"
#import "WCNPatientStatusTCell.h"
#import "WSJPickAndCustomSegment.h"
#import "UMMobClick/MobClick.h"
#import "MJRefreshConst.h"
#import "Constants.h"

static NSString *cell1 = @"WCNMulTextTCell";
static NSString *cell2 = @"WCNSwitchSexTCell";
static NSString *cell3 = @"WCNPatientStatusTCell";


@interface WCNNewPICCPreserveVC ()

@property (nonatomic,  strong) NSArray *titleArray;

@property (nonatomic,  strong) WCNMulTextTCell *dynamicHeightCell;

@property (nonatomic,  strong) WSJCareNursingPeopleView *nurseScrollView;
//@property (weak, nonatomic) UIView *mainNurseView;

@property (nonatomic,  assign) BOOL canSwitchMainNurse;

@property (nonatomic,  strong) WCNNurseModel *mainNurse;
//@property (weak, nonatomic) UIButton *addAssistNursesButton;
@property (strong, nonatomic) NSMutableArray *assistNurses;
//@property (strong, nonatomic) NSMutableArray *assistNurseImageViews;

@property (nonatomic,  assign) BOOL isFold;


@end

@implementation WCNNewPICCPreserveVC

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        self.mainNurse = [WCNNurseModel new];
        Account *accout =[[WCDefaultManager shareMg] account];
        self.mainNurse.avatarFileId = accout.avatarFileId;
        self.mainNurse.stringId = accout.stringId;
        self.mainNurse.requestStatus = 1;
        self.mainNurse.name = accout.name;
        self.assistNurses = [NSMutableArray arrayWithObject:self.mainNurse];
        self.isFold = YES;
    }
    return self;
}
- (void)pageBack{
    defineWeakSelf;
    [JCAlertView showTwoButtonsWithTitle:@"提示" Message:@"是否放弃编辑" ButtonType:2 ButtonTitle:@"放弃编辑" Click:^{
        [weakSelf.navigationController popViewControllerAnimated:YES];
    } ButtonType:0 ButtonTitle:@"继续编辑" Click:^{
        
    }];
 
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    [self configNav];
    
    
    self.patient = [WCNMyPatientModel new];
    self.patient.piccInfo = [WCNPiccInforSubModel new];
    
    if (self.vcType == 0) {
         self.title = @"新增PICC患者";
         self.patient.piccInfo.nursingStatus = @"MONITORING";
          self.patient.piccInfo.inputCount = @"第一次";

    }else if (self.vcType == 1){
        [self postPiccRecordDetail];
         self.title = @"修改PICC患者";
        self.isFold = NO;
    }
    
}

- (void)checkParams{

    if (!self.patient.name) {
        WSJSHOW(@"姓名为空~");
        return;
    }
    if (!self.patient.birthday) {
        WSJSHOW(@"出生日期为空~");
        return;
    }
//    if (!self.patient.sex) {
//        WSJSHOW(@"临床诊断为空~");
//        return;
//    }
    if (!self.patient.piccInfo.clinicalDiagnosis) {
        WSJSHOW(@"临床诊断为空~");
        return;
    }
//    if (!self.patient.piccInfo.inputDate) {
//        WSJSHOW(@"PICC置入日期为空~");
//        return;
//    }
    if (!self.patient.hosPatientNo &&!self.patient.outPatientNo) {
        WSJSHOW(@"住院号和门诊号不能同时为空~");
        return;
    }
    weakSelf_define;
    [JCAlertView showTwoButtonsWithTitle:@"提示" Message:@"是否提交信息" ButtonType:0 ButtonTitle:@"继续编辑" Click:^{
       
        
    } ButtonType:1 ButtonTitle:@"是" Click:^{
        if (weakSelf.vcType ==1) {
            [weakSelf modifyPiccRecord];
        }else{
            [weakSelf postToAddPost];
        }
        
    }];
    
    
}
#pragma mark -上传新增picc信息
- (void)postToAddPost{
    
    //    必填 :
    //name: 患者姓名
    //age: 患者年龄
    //sex: 患者性别(0:男 ,1:女)
    //hosPatientNo: 住院号 outPatientNo: 门诊号(二者选填其一)
    //clinicalDiagnosis: 临床诊断
    //createBy: 创建者
    //nurseMembers: 共同护理人(护士ID以,号分割拼接)
    //recordType: 患者档案ID类型(1:伤口档案ID,2:PICC档案ID)
    //    选填 :
    //inputDate: PICC置入日期 (格式'2016-03-30')
    
    NSMutableDictionary *params =[NSMutableDictionary dictionary];
    //设置护理人(主护理人和共同护理人)
    NSMutableArray *nurseIds = [NSMutableArray array];
    for (id nurse in self.assistNurses) {
        [nurseIds addObject:[nurse valueForKey:@"stringId"]];
    }
    NSMutableString *ids = [NSMutableString stringWithString:[nurseIds componentsJoinedByString:@","]];
    self.patient.nurseMembers= ids;
    NSDictionary  *dict1 = [self.patient keyValues];
    NSDictionary  *dict2 = [self.patient.piccInfo keyValues];
    
    [params addEntriesFromDictionary:dict1];
    [params addEntriesFromDictionary:dict2];
    
    params[@"createBy"]= @([[WCDefaultManager shareMg] nurseId]);
   
    params[@"recordType"] = @(2);
    CoreSVPLoading(@"上传中...", NO);
    weakSelf_define;
    [[WCNetworkAccessManager sharedMg] POST:kAddPiccPatient parameters:params success:^(NSDictionary *responseObject) {
        CoreSVPSuccess(responseObject[@"data"]);
        //统计新增picc患者
        [MobClick event:AddPICCPatient];
        if (weakSelf.isAutoRefresh) {
            weakSelf.isAutoRefresh();
        }
        
        [weakSelf.navigationController popViewControllerAnimated:YES];
    } failure:nil netError:nil always:^{
        [CoreSVP dismiss];
    }];
    


}

#pragma mark -获取患者档案详情
- (void)postPiccRecordDetail{
    
    defineWeakSelf;
    CoreSVPLoading(@"加载中...", NO);
    
    [[WCNetworkAccessManager sharedMg] GET:[NSString stringWithFormat:@"%@/%d",kPiccRecordDetail,self.piccRecordId] parameters:nil success:^(NSDictionary *responseObject) {

              weakSelf.patient = [WCNMyPatientModel objectWithKeyValues:responseObject[@"data"][@"patientPiccRecord"]];
        weakSelf.patient.piccInfo = [WCNPiccInforSubModel objectWithKeyValues:responseObject[@"data"][@"patientPiccRecord"]];
        NSArray *nurseArr =responseObject[@"data"][@"patientNursingMember"];
        if ([nurseArr isKindOfClass:[NSArray class]]) {
            for (NSDictionary *nurseDict in nurseArr) {
                if ([nurseDict[@"isPrimary"] isEqualToString:@"YES"]) {
                    weakSelf.mainNurse.stringId = [NSString stringWithFormat:@"%@",nurseDict[@"nurseId"]];
                    weakSelf.mainNurse.isPrimary = 1;
                    weakSelf.mainNurse.requestStatus = 1;
                    weakSelf.mainNurse.name = nurseDict[@"name"];
                    weakSelf.mainNurse.requestStatus =[nurseDict[@"requestStatus"] integerValue];
                }else{
                    WCNNurseModel *nurse =[[WCNNurseModel alloc] init];
                    nurse.stringId  =[NSString stringWithFormat:@"%@",nurseDict[@"nurseId"]];
                    nurse.name = nurseDict[@"name"];
                    nurse.isPrimary = 0;
                    nurse.requestStatus =[nurseDict[@"requestStatus"] integerValue];
                    [weakSelf.assistNurses addObject:nurse];
                }
            }
        }
        
        weakSelf.nurseScrollView.dataArray =weakSelf.assistNurses;
//        [weakSelf loadOrReAssistNurses];
        
        [weakSelf.tableView reloadData];
    } failure:nil netError:nil always:^{
         [CoreSVP dismiss];
        
    }];

    
    
}
#pragma mark -修改患者档案
- (void)modifyPiccRecord{
    defineWeakSelf;
    CoreSVPLoading(@"加载中...", NO);
    NSMutableDictionary *params =[NSMutableDictionary dictionary];
    //设置护理人(主护理人和共同护理人)
    NSMutableArray *nurseIds = [NSMutableArray array];
    for (id nurse in self.assistNurses) {
        [nurseIds addObject:[nurse valueForKey:@"stringId"]];
    }
    NSMutableString *ids = [NSMutableString stringWithString:[nurseIds componentsJoinedByString:@","]];
    self.patient.nurseMembers= ids;

    NSDictionary  *dict1 = [self.patient keyValues];
    NSDictionary  *dict2 = [self.patient.piccInfo keyValues];
    
    [params addEntriesFromDictionary:dict1];
    [params addEntriesFromDictionary:dict2];
    
    params[@"id"] = @(self.piccRecordId);
    [[WCNetworkAccessManager sharedMg] POST:kModifyPiccRecord parameters:params success:^(NSDictionary *responseObject) {
        //统计修改picc患者
        [MobClick event:MotifyPICCPatient];
        CoreSVPSuccess(responseObject[@"data"]);
        if (weakSelf.isAutoRefresh) {
            weakSelf.isAutoRefresh();
        }
        [weakSelf.navigationController popViewControllerAnimated:YES];
        
    } failure:nil netError:nil always:^{
        [CoreSVP dismiss];
    }];
   
}
//姓名 性别年龄 住院号 门诊号 临床诊断 置入PICC日期 穿刺信息
- (NSArray *)titleArray{
    
    if (self.isFold==YES) {
        _titleArray =@[@"姓名",@"性别",@"出生日期",@"住院号",@"门诊号",@"状态",@"临床诊断",@"置入PICC日期",@"第几次置管",@"穿刺信息"];
    }else{
        _titleArray =@[@"姓名",@"性别",@"出生日期",@"住院号",@"门诊号",@"状态",@"临床诊断",@"置入PICC日期",@"第几次置管",@"穿刺信息",@"穿刺方式", @"穿刺手臂",@"穿刺静脉",@"首次置入体内长度",@"外露长度(不包括接头)",@"PICC导管末端位置",@"臂围",@"穿刺者医院",@"穿刺者姓名",@"导管类型",@"导管型号",@"导管生产商",@"条形编码",@"其他"];
        
    }
    
    return _titleArray;
}
- (void)configNav{
    self.canSwitchMainNurse = NO;
    //新增可以切换主护理师
    if (!self.patient.stringId) {
        self.canSwitchMainNurse = YES;
      
       
    } else {
        Account *account = [[WCDefaultManager shareMg] account];
        //编辑时只有主护理师才可以切换主护理师
        if ([self.mainNurse.stringId isEqual:account.stringId]) {
            self.canSwitchMainNurse = YES;
        }
    }
    self.view.backgroundColor =[UIColor whiteColor];
    
    WCButton *rightBtn = [WCButton wcButtonWithType:WCButtonTypeSave];
    [rightBtn addTarget:self action:@selector(save) forControlEvents:UIControlEventTouchUpInside];
    [self.navigationItem addRightBarButtonItem:rightBtn];
    [self.tableView registerNib:[UINib nibWithNibName:cell1 bundle:nil] forCellReuseIdentifier:cell1];
    [self.tableView registerNib:[UINib nibWithNibName:cell2 bundle:nil] forCellReuseIdentifier:cell2];
    [self.tableView registerNib:[UINib nibWithNibName:cell3 bundle:nil] forCellReuseIdentifier:cell3];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    UIView *tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 70+98+98+34)];
    [self loadFooterView:tableFooterView];
    self.tableView.tableFooterView = tableFooterView;
    self.dynamicHeightCell = [self.tableView dequeueReusableCellWithIdentifier:cell1];
    [self.dynamicHeightCell.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.dynamicHeightCell.contentView
                                                                                   attribute:NSLayoutAttributeWidth
                                                                                   relatedBy:NSLayoutRelationEqual
                                                                                      toItem:nil
                                                                                   attribute:NSLayoutAttributeNotAnAttribute
                                                                                  multiplier:1
                                                                                    constant:kScreenWidth]];
    self.dynamicHeightCell.mulText.numberOfLines = 0;
}

- (void)save{
    [self checkParams];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.titleArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    weakSelf_define;
    UITableViewCell *idCell;
    
    if (indexPath.row==1) {
          WCNSwitchSexTCell *sexCell = [tableView dequeueReusableCellWithIdentifier:cell2 forIndexPath:indexPath];
        if (!self.patient.sex) {
            self.patient.sex = NO;
        }
        [sexCell setSex:self.patient.sex];
       
        sexCell.sexValueChange = ^(BOOL isMale){
            weakSelf.patient.sex = isMale;
           
            
        };
        idCell   =sexCell;
        
    }else if (indexPath.row ==5){
        //状态cell
        WCNPatientStatusTCell *statusCell = [tableView dequeueReusableCellWithIdentifier:cell3 forIndexPath:indexPath];
        statusCell.selectionStyle = UITableViewCellSelectionStyleNone;
        weakSelf_define;
        statusCell.btnClick = ^(NSString *status){
            weakSelf.patient.piccInfo.nursingStatus = status;
        };
        
        NSString *status = self.patient.piccInfo.nursingStatus;
        if (status) {
            [statusCell setStatus:status];
        }
        idCell  =statusCell;
    
    }else{
        WCNMulTextTCell *normalCell = [tableView dequeueReusableCellWithIdentifier:cell1 forIndexPath:indexPath];
        normalCell.mulText.text  = @"";
        normalCell.arowImg.image = [UIImage imageNamed:@"Arrow_Right"];
        normalCell.mulText.textAlignment = NSTextAlignmentRight;
        normalCell.backgroundColor = [UIColor whiteColor];
        normalCell.textTitle.text = self.titleArray[indexPath.row];
        normalCell.mulText.textColor= kTxtColor;
        switch (indexPath.row) {
            case 0:{
                
                
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.name initText:@""];
                break;
            }
            case 2:{
                
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.birthday initText:@""];
                
                
                break;
            }
            case 3:{
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.hosPatientNo initText:@""];
               
                break;
            }
            case 4:{
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.outPatientNo initText:@""];
              
                break;
            }
                
            case 6:{
                //                        diagnosis
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.piccInfo. clinicalDiagnosis initText:@""];
                normalCell.mulText.text = self.patient.piccInfo. clinicalDiagnosis;
                break;
            }
                
            case 7:{
                
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.piccInfo.inputDate initText:@""];
                break;
            }
            case 8:{
                
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.piccInfo.inputCount initText:@"第一次"];
                break;
            }
                
            case 9:{
                if (!self.isFold) {
                    normalCell.arowImg.image = [UIImage imageNamed:@"Arrow_Down"];
                    normalCell.mulText.text= @"点击折叠";
                    normalCell.mulText.textColor = [UIColor redColor];
                    
                }else{
                    normalCell.mulText.textColor= [UIColor redColor];
                    normalCell.mulText.text = @"点击展开";
                }
                
                
                //                        [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.piccInfo.picc_type initText:@""];
                break;
            }
            case 10:{
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.piccInfo.punctureType initText:@""];
                normalCell.backgroundColor = kAppBg;
                break;
            }
            case 11:{
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.piccInfo.punctureArm initText:@""];
                
                normalCell.backgroundColor = kAppBg;
                break;
            }
            case 12:{
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.piccInfo.punctureVein initText:@""];
                
                normalCell.backgroundColor = kAppBg;
                break;
            }
            case 13:{
                [WCTSetTextTool setTextView:normalCell.mulText text:[NSString stringWithFormat:@"%@CM",self.patient.piccInfo.firstIntoBodyLength] initText:@"CM"];
                
                normalCell.backgroundColor = kAppBg;
                break;
            }
            case 14:{
                [WCTSetTextTool setTextView:normalCell.mulText text:[NSString stringWithFormat:@"%@CM",self.patient.piccInfo.outBodyLength] initText:@"CM"];
                
                normalCell.backgroundColor = kAppBg;
                break;
            }
            case 15:{
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.piccInfo.piccCatheterEndSize initText:nil];
                normalCell.backgroundColor = kAppBg;
                break;
            }
            case 16:{
                [WCTSetTextTool setTextView:normalCell.mulText text:[NSString stringWithFormat:@"%@CM",self.patient.piccInfo.armLength] initText:@"CM"];
                normalCell.backgroundColor = kAppBg;
                break;
            }
            case 17:{
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.piccInfo.piercerHospitalName initText:@""];
                
                normalCell.backgroundColor = kAppBg;
                break;
            }
            case 18:{
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.piccInfo.piercerName initText:@""];
                
                normalCell.backgroundColor = kAppBg;
                break;
            }
            case 19:{
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.piccInfo.catheterModel initText:@""];
                normalCell.backgroundColor = kAppBg;
                break;
            }
            case 20:{
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.piccInfo.catheterType initText:@""];
                
                normalCell.backgroundColor = kAppBg;
                break;
            }
            case 21:{
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.piccInfo.catheterProducer initText:@""];
                normalCell.backgroundColor = kAppBg;
                break;
            }
            case 22:{
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.piccInfo.barCode initText:@""];
                
                normalCell.backgroundColor = kAppBg;
                break;
            }
            case 23:{
                [WCTSetTextTool setTextView:normalCell.mulText text:self.patient.piccInfo.other initText:@""];
                normalCell.backgroundColor = kAppBg;
                break;
            }
                
                
                
        }
        
        [normalCell setSeparatorInset:UIEdgeInsetsZero];
        if ([normalCell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
            [normalCell setPreservesSuperviewLayoutMargins:NO];
        }
        if ([normalCell respondsToSelector:@selector(setLayoutMargins:)]) {
            [normalCell setLayoutMargins:UIEdgeInsetsZero];
        }
        normalCell.selectionStyle = UITableViewCellSelectionStyleNone;
        idCell = normalCell;
    }
    
    return idCell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row==0) {
        self.dynamicHeightCell.mulText.text =self.patient.piccInfo.clinicalDiagnosis?self.patient.  piccInfo.clinicalDiagnosis:@"" ;
        CGSize size = [self.dynamicHeightCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
        [self.dynamicHeightCell.mulText showAttributedText:0 lineSpace:5];
        return MAX(kOnePX+size.height, 46.0);
    }else if (indexPath.row ==21){
        self.dynamicHeightCell.mulText.text =self.patient.piccInfo.other?self.patient.piccInfo.other:@"" ;
        CGSize size = [self.dynamicHeightCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
        [self.dynamicHeightCell.mulText showAttributedText:0 lineSpace:5];
        return MAX(kOnePX+size.height, 46.0);
    }else if(indexPath.row == 5){
        return 150;
    }
    return 46;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    weakSelf_define;
    WCNMulTextTCell *cell = (WCNMulTextTCell *)[tableView cellForRowAtIndexPath:indexPath];
    switch (indexPath.row) {
        case 0:{
            WCInfoEditView *editView = [[WCInfoEditView alloc] init];
            editView.titleLabel.text = @"编辑姓名";
            [WCTSetTextTool setTextView:editView.textField text:self.patient.name initText:@""];
            
            editView.save = ^(NSString *txt){
                if (![txt isEmpty]) {
                    //                    self.patient[@"name"] = txt;
                    weakSelf.patient.name = txt;
                    cell.mulText.text = txt;
                    return YES;
                }
                return NO;
            };
            [editView showIn:self.navigationController.view animated:YES];
            break;
        }
        case 2:{
            WCDatePickerView *datePicker = [[WCDatePickerView alloc] init];
            datePicker.dateLabel.text = @"选择出生日期";
            
            datePicker.datePicker.maximumDate = [NSDate date];
            datePicker.close = ^(NSDate *date){
                weakSelf.patient.birthday = [date stringWithFormat:@"yyyy-MM-dd"];
                cell.mulText.text = [date stringWithFormat:@"yyyy-MM-dd"];
            };
            [datePicker show:self.navigationController completion:nil];
            
            
            
//            WCPickerView *picker = [[WCPickerView alloc] init];
//            picker.titleLabel.text = @"年龄";
//            picker.pickerDataSource = ages;
//            //选中
//            [picker.picker selectRow:index inComponent:0 animated:YES];
//            picker.close = ^(NSInteger selected){
//                weakSelf.patient.age= [NSString stringWithFormat:@"%@",ages[selected]];
//                cell.mulText.text = ages[selected];
//            };
//            [picker show:self.navigationController completion:nil];
            break;
        }
        case 3:{
            WCInfoEditView *editView = [[WCInfoEditView alloc] init];
            editView.titleLabel.text = @"输入住院号";
            editView.type = WCInfoEditTypeInteger;
            editView.limitLenth = 10;
            [WCTSetTextTool setTextView:editView.textField text:self.patient.hosPatientNo initText:@""];
            
            //            editView.textField.text = self.patient[@"name"];
            editView.save = ^(NSString *txt){
                if (![txt isEmpty]) {
                    weakSelf.patient.hosPatientNo= txt;
                    cell.mulText.text = txt;
                    return YES;
                }
                return NO;
            };
            [editView showIn:self.navigationController.view animated:YES];
            break;
        }
        case 4:{
            WCInfoEditView *editView = [[WCInfoEditView alloc] init];
            editView.titleLabel.text = @"输入门诊号";
            editView.type = WCInfoEditTypeInteger;
            editView.limitLenth = 10;
            
            [WCTSetTextTool setTextView:editView.textField text:self.patient.outPatientNo initText:@""];
            //            editView.textField.text = self.patient[@"name"];
            editView.save = ^(NSString *txt){
                if (![txt isEmpty]) {
                    //                    self.patient[@"name"] = txt;
                    cell.mulText.text = txt;
                    
                    weakSelf.patient.outPatientNo = txt;
                    return YES;
                }
                return NO;
            };
            [editView showIn:self.navigationController.view animated:YES];
            break;
        }case 6:{
            WCNMulTextEditVC *vc = [[WCNMulTextEditVC alloc] initWithType:WCNMulTextEditSave];
            vc.title = @"临床诊断";
            vc.canEmpty = NO;
            vc.textViewPlaceholder = @"请填写诊断";
            
            vc.textViewValue = self.patient.piccInfo.clinicalDiagnosis?self.patient.piccInfo.clinicalDiagnosis:@"";
            vc.textViewEmptyWarm = @"请填写诊断";
            vc.callback = ^(NSString *txt){
                weakSelf.patient.piccInfo.clinicalDiagnosis = txt;
                [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
            };
            [self.navigationController pushViewController:vc animated:YES];
            break;
            
            
        }
        case 7:{
            WCDatePickerView *datePicker = [[WCDatePickerView alloc] init];
            datePicker.dateLabel.text = @"选择置入PICC日期";
        
            datePicker.datePicker.maximumDate = [NSDate date];
            datePicker.close = ^(NSDate *date){
                weakSelf.patient.piccInfo.inputDate = [date stringWithFormat:@"yyyy-MM-dd"];
                cell.mulText.text = [date stringWithFormat:@"yyyy-MM-dd"];
            };
            [datePicker show:self.navigationController completion:nil];
            break;
            
        }
        case 8:{
            WSJPickView *picker =[WSJPickView pickView];
            
            picker.dataArray =@[@"第一次",@"第二次",@"第三次",@"第四次",@"第五次"];
            picker.pickTitle = @"第几次置管";
            picker.saveBlock= ^(NSString *selecStr,NSInteger index){
                weakSelf.patient.piccInfo.inputCount = selecStr;
                cell.mulText.text = selecStr;
                //              [WCTSetTextTool setTextView:cell.mulText text:self.patient.piccInfo.picc_type initText:@""];
            };
            [picker show];
            
            
            break;
            
           
        }
        case 9:{
            self.isFold =!self.isFold;
            [self.tableView reloadData];
            
            break;
            
        }
        case 10:{
            WSJPickView *picker =[WSJPickView pickView];
            
            picker.dataArray =@[@"传统",@"MST",@"超声引导"];
            picker.pickTitle = @"穿刺方式选择";
            picker.saveBlock= ^(NSString *selecStr,NSInteger index){
                weakSelf.patient.piccInfo.punctureType = selecStr;
                cell.mulText.text = selecStr;
                //              [WCTSetTextTool setTextView:cell.mulText text:self.patient.piccInfo.picc_type initText:@""];
            };
            [picker show];
            
            break;
        }
        case 11:{
            WSJPickView *picker =[WSJPickView pickView];
            
            picker.dataArray =@[@"左臂",@"右臂"];
            picker.pickTitle = @"穿刺手臂";
            picker.saveBlock= ^(NSString *selecStr,NSInteger index){
                weakSelf.patient.piccInfo.punctureArm = selecStr;
                cell.mulText.text = selecStr;
                //              [WCTSetTextTool setTextView:cell.mulText text:self.patient.piccInfo.picc_type initText:@""];
            };
            [picker show];
            
            
            break;
        }
        case 12:{
            WSJPickView *picker =[WSJPickView pickView];
            
            picker.dataArray =@[@"贵要静脉",@"正中静脉",@"头静脉",@"肱静脉"];
            picker.pickTitle = @"穿刺静脉";
            picker.saveBlock= ^(NSString *selecStr,NSInteger index){
                weakSelf.patient.piccInfo.punctureVein = selecStr;
                cell.mulText.text = selecStr;
                //              [WCTSetTextTool setTextView:cell.mulText text:self.patient.piccInfo.picc_type initText:@""];
            };
            [picker show];
            
            break;
        }
        case 13:{
            WCInfoEditView *editView = [[WCInfoEditView alloc] init];
            editView.titleLabel.text = @"首次置入体内长度";
            editView.type = WCInfoEditTypeMoney;
            editView.limitLenth = 8;
            //            editView.textField.text = self.patient[@"name"];
            editView.save = ^(NSString *txt){
                if (![txt isEmpty]) {
                    //                    self.patient[@"name"] = txt;
//                    cell.mulText.text = txt;
                    weakSelf.patient.piccInfo.firstIntoBodyLength = txt;
                    [weakSelf.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationFade];
                    return YES;
                }
                return NO;
            };
            [editView showIn:self.navigationController.view animated:YES];
            
            
            
            break;
        }
        case 14:{
            WCInfoEditView *editView = [[WCInfoEditView alloc] init];
            editView.titleLabel.text = @"外露长度";
            editView.type = WCInfoEditTypeMoney;
            editView.limitLenth = 8;
            //            editView.textField.text = self.patient[@"name"];
            editView.save = ^(NSString *txt){
                if (![txt isEmpty]) {
                    //                    self.patient[@"name"] = txt;
//                    cell.mulText.text = txt;
                    weakSelf.patient.piccInfo.outBodyLength = txt;
                    [weakSelf.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationFade];
                    return YES;
                }
                return NO;
            };
            [editView showIn:self.navigationController.view animated:YES];
            
            
            
            
            break;
        }
        case 15:{
            WSJPickAndCustomSegment *pickVC = [[WSJPickAndCustomSegment alloc] init];
            pickVC.dataSourceArray = @[@"腋下", @"锁骨下", @"上腔静脉"];
            pickVC.callBack = ^(NSString *text, NSInteger item){
                
                weakSelf.patient.piccInfo.piccCatheterEndSize = text;
                [weakSelf.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationFade];

            };
            [self presentViewController:pickVC animated:YES completion:nil];
//            WCInfoEditView *editView = [[WCInfoEditView alloc] init];
//            editView.titleLabel.text = @"PICC导管末端位置";
//            editView.type = WCInfoEditTypeText;
//            [WCTSetTextTool setTextView:editView.textField text:self.patient.piccInfo.piccCatheterEndSize initText:@""];
//            editView.limitLenth = 20;
//            //            editView.textField.text = self.patient[@"name"];
//            editView.save = ^(NSString *txt){
//                if (![txt isEmpty]) {
//                    //                    self.patient[@"name"] = txt;
//                   
//                    weakSelf.patient.piccInfo.piccCatheterEndSize = txt;
//                     [weakSelf.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationFade];
//                    return YES;
//                }
//                return NO;
//            };
//            [editView showIn:self.navigationController.view animated:YES];
            
            break;
        }
        case 16:{
            WCInfoEditView *editView = [[WCInfoEditView alloc] init];
            editView.titleLabel.text = @"臂围";
            editView.type = WCInfoEditTypeMoney;
            [WCTSetTextTool setTextView:editView.textField text:self.patient.piccInfo.armLength initText:@""];
            editView.limitLenth = 8;
            //            editView.textField.text = self.patient[@"name"];
            editView.save = ^(NSString *txt){
                if (![txt isEmpty]) {
                    //                    self.patient[@"name"] = txt;
//                    cell.mulText.text = txt;
                    weakSelf.patient.piccInfo.armLength = txt;
                    
                    [weakSelf.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section]] withRowAnimation:UITableViewRowAnimationFade];
                    return YES;
                }
                return NO;
            };
            [editView showIn:self.navigationController.view animated:YES];
            break;
        }
        case 17:{
            WCInfoEditView *editView = [[WCInfoEditView alloc] init];
            editView.titleLabel.text = @"穿刺者医院";
            [WCTSetTextTool setTextView:editView.textField text:self.patient.piccInfo.piercerHospitalName initText:@""];
            //            editView.textField.text = self.patient[@"name"];
            editView.save = ^(NSString *txt){
                if (![txt isEmpty]) {
                    //                    self.patient[@"name"] = txt;
                    cell.mulText.text = txt;
                    weakSelf.patient.piccInfo.piercerHospitalName =txt;
                    return YES;
                }
                return NO;
            };
            [editView showIn:self.navigationController.view animated:YES];
            
            
            
            break;
        }
        case 18:{
            WCInfoEditView *editView = [[WCInfoEditView alloc] init];
            editView.titleLabel.text = @"穿刺者姓名";
            //            editView.textField.text = self.patient[@"name"];
            [WCTSetTextTool setTextView:editView.textField text:self.patient.piccInfo.piercerName initText:@""];
            editView.save = ^(NSString *txt){
                if (![txt isEmpty]) {
                    //                    self.patient[@"name"] = txt;
                    cell.mulText.text = txt;
                    weakSelf.patient.piccInfo.piercerName =txt;
                    return YES;
                }
                return NO;
            };
            [editView showIn:self.navigationController.view animated:YES];
            
            
            
            
            break;
        }
        case 19:{
            WSJPickView *picker =[WSJPickView pickView];
            //           瓣膜式、开口式、耐压
            picker.dataArray =@[@"瓣膜式",@"开口式",@"耐压"];
            picker.pickTitle = @"导管类型";
            picker.saveBlock= ^(NSString *selecStr,NSInteger index){
                weakSelf.patient.piccInfo.catheterModel = selecStr;
                cell.mulText.text = selecStr;
                
            };
            [picker show];
            
            
            break;
        }
        case 20:{
            WSJPickView *picker =[WSJPickView pickView];
            //            4F、5F、双腔
            picker.dataArray =@[@"4F",@"5F",@"双腔"];
            picker.pickTitle = @"导管型号";
            picker.saveBlock= ^(NSString *selecStr,NSInteger index){
                weakSelf.patient.piccInfo.catheterType = selecStr;
                cell.mulText.text = selecStr;
                
            };
            [picker show];
            
            break;
            
            
            
            break;
        }
        case 21:{
            WCInfoEditView *editView = [[WCInfoEditView alloc] init];
            editView.titleLabel.text = @"导管生产商";
            //            editView.textField.text = self.patient[@"name"];
            [WCTSetTextTool setTextView:editView.textField text:self.patient.piccInfo.catheterProducer initText:@""];
            editView.save = ^(NSString *txt){
                if (![txt isEmpty]) {
                    //                    self.patient[@"name"] = txt;
                    cell.mulText.text = txt;
                    weakSelf.patient.piccInfo.catheterProducer =txt;
                    return YES;
                }
                return NO;
            };
            [editView showIn:self.navigationController.view animated:YES];
            
            
            break;
        }
        case 22:{
            WCInfoEditView *editView = [[WCInfoEditView alloc] init];
            editView.titleLabel.text = @"条件编码";
            //            editView.textField.text = self.patient[@"name"];
            [WCTSetTextTool setTextView:editView.textField text:self.patient.piccInfo.barCode initText:@""];
            editView.save = ^(NSString *txt){
                if (![txt isEmpty]) {
                    //                    self.patient[@"name"] = txt;
                    cell.mulText.text = txt;
                    weakSelf.patient.piccInfo.barCode =txt;
                    return YES;
                }
                return NO;
            };
            [editView showIn:self.navigationController.view animated:YES];
            
            
            break;
        }
        case 23:{
            WCNMulTextEditVC *vc = [[WCNMulTextEditVC alloc] initWithType:WCNMulTextEditSave];
            vc.title = @"PICC 其他";
            vc.canEmpty = NO;
            vc.textViewPlaceholder = @"其他描述";
            
            vc.textViewValue = self.patient.piccInfo.other?self.patient.piccInfo.other:@"";
            vc.textViewEmptyWarm = @"描述";
            vc.callback = ^(NSString *txt){
                weakSelf.patient.piccInfo.other = txt;
                [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
            };
            [self.navigationController pushViewController:vc animated:YES];
            
            
            break;
        }
            
        default:
            break;
    }
    
    
}
#pragma mark - 加载底部图片编辑

- (void)loadFooterView:(UIView *)tableFooterView
{
    
    defineWeakSelf;
    WCDrawBorderView *view1 = [[WCDrawBorderView alloc] initWithFrame:CGRectMake(0, -kOnePX, kScreenWidth, 45+kOnePX)];
    view1.topBorder = YES;
    view1.borderColor = kBorderColor;
    
    view1.backgroundColor = [UIColor whiteColor];
    [tableFooterView addSubview:view1];
    
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(14, 10, 200, 25)];
    label1.font = [UIFont systemFontOfSize:16.0];
    label1.text = @"主护理和共同护理人";
    [view1 addSubview:label1];
    
    UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth-11-13, 16, 13, 13)];
    imageView1.image = [UIImage imageNamed:@"Arrow_Down"];
    [view1 addSubview:imageView1];
    if (!self.nurseScrollView) {
        self.nurseScrollView  = [[WSJCareNursingPeopleView alloc] initWithFrame:CGRectMake(0, 60, kScreenWidth,  98 +34 +98)];
        
        self.nurseScrollView.dataArray =self.assistNurses;
        [tableFooterView addSubview:self.nurseScrollView];
        self.nurseScrollView.addNewBlok =^(){
                WCNHospitalListVC *hospitalVC =[WCNHospitalListVC new];
            
                hospitalVC.unableSelectArray = [NSArray arrayWithArray:weakSelf.assistNurses] ;
            
                hospitalVC.popCallBack = ^(NSArray *selectItems){
                    for (WCNNurseModel *nurse in selectItems) {
                        nurse.requestStatus = 2;
                        [weakSelf.assistNurses addObject:nurse];

                    }
                    
                    weakSelf.nurseScrollView.dataArray = [NSArray arrayWithArray:weakSelf.assistNurses];
                    
                };
                [weakSelf.navigationController pushViewController:hospitalVC animated:YES];
                

            
        };
        self.nurseScrollView.deleNurse  =^(WCNNurseModel *model){
            for (id nurse in weakSelf.assistNurses) {
                if ([[nurse valueForKey:@"stringId"] isEqualToString:model.stringId]) {
                    [weakSelf.assistNurses removeObject:nurse];
                    break;
                }
                
            }
        };
        

    }
    
}
@end
